
import 'package:enjoy_plus_three/utils/http.dart';
import 'package:enjoy_plus_three/utils/logger.dart';
import 'package:enjoy_plus_three/utils/toast.dart';
import 'package:flutter/material.dart';

import 'components/home_list.dart';
import 'components/home_nav.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  List notifyList = [];

  @override
  void initState() {
    // 获取公告数据
      getNotifyList();
    super.initState();
  }

  void getNotifyList () async{
      //发请求
      final res =  await http.get('/announcement');
      if(res['code'] != 10000) return ToastUtil.showError('数据获取失败');
      ToastUtil.showSuccess('数据获取成功');
      setState(() {
        notifyList = res['data'];
      });
      logger.i(res);
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromARGB(40, 85, 145, 175),
      appBar: AppBar(
        title: const Text('享+社区'),
        backgroundColor: Colors.transparent,
        centerTitle: true,
      ),
      body: ListView(
        scrollDirection: Axis.vertical,
        padding: const EdgeInsets.all(10),
        children:  [
          // 导航条
          HomeNav(),
          // 中间广告图
          ClipRRect(
            borderRadius: BorderRadius.circular(10.0),
            child: Image.asset('images/banner@2x.jpg'),
          ),
          // 社区公告
            HomeList(notifyList:notifyList,)
        ],
      )
    );
  }
}